#include "GdiPlusGraphics.h"
GdiPlusGraphics::GdiPlusGraphics()
{
	//Khoi tao thu vien Gdiplus
	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;

	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
	HWND console = GetConsoleWindow();
	
	//Doi tuong graphics gan voi cua so console
	g = new Graphics(console);
}
void GdiPlusGraphics::drawLine(int x1, int y1, int x2, int y2, string stroke, int strokeWidth)
{
	string _stroke = stroke;
	//Xu ly chuoi string stroke tu rbg(,,) sang a1,a2,a3
	int a1 = Parse(stroke);
	int a2 = Parse(stroke);
	int a3 = Parse(stroke);

	//Tao pen va ve duong thang
	Pen p(Color(a1,a2,a3),strokeWidth);
	g->DrawLine(&p, x1, y1, x2, y2);

	//Luu line nay vao trong chuoi listObjects de co the Save tap tin
	stringstream list;
	list << "<line x1=" << "\"" << x1 << "\"" << " y1=" << "\"" << y1 << "\"";
	list << " x2=" << "\"" << x2 << "\"" << " y2=" << "\"" << y2 << "\"";
	list << " stroke=" << "\"" << _stroke << "\""; 
	list << " stroke-width=" << "\"" << strokeWidth << "\"" << "/>";
	getListObjects() += list.str();
}

void GdiPlusGraphics::drawRectangle(int x, int y, int width, int height, string stroke, int strokeWidth, string fill)
{
	string _stroke = stroke;
	string _fill = fill;

	//Xu ly chuoi string stroke tu rbg(,,) sang a1, a2, a3
	int a1 = Parse(stroke);
	int a2 = Parse(stroke);
	int a3 = Parse(stroke);

	//Xu ly chuoi string fill tu rgb(,,) sang b1, b2, b3
	int b1 = Parse(fill);
	int b2 = Parse(fill);
	int b3 = Parse(fill);	
	
	//Tao pen va ve hinh chu nhat
	Pen p(Color(a1,a2,a3),strokeWidth);
	g->DrawRectangle(&p,x,y,width,height);

	//Luu hinh chu nhat nay vao trong chuoi listObjects de co the Save tap tin
	stringstream list;
	list << "<rect x=" << "\"" << x << "\"" << " y=" << "\"" << y << "\"";
	list << " width=" << "\"" << width << "\"" << " height=" << "\"" << height << "\"";
	list << " stroke=" << "\"" << _stroke << "\""; 
	list << " stroke-width=" << "\"" << strokeWidth << "\"";
	list << " fill=" << "\"" << _fill << "\"" << "/>";
	getListObjects() += list.str();
}

void GdiPlusGraphics::drawEllipse(int cx, int cy, int rx, int ry, string stroke, int strokeWidth, string fill)
{
	string _stroke = stroke;
	string _fill = fill;
	//Xu ly chuoi string stroke tu rbg(,,) sang a1, a2, a3
	int a1 = Parse(stroke);
	int a2 = Parse(stroke);
	int a3 = Parse(stroke);

	//Xu ly chuoi string fill tu rgb(,,) sang b1, b2, b3
	int b1 = Parse(fill);
	int b2 = Parse(fill);
	int b3 = Parse(fill);	
	
	//Tao pen va ve hinh ellipse
	Pen p(Color(a1,a2,a3),strokeWidth);
	g->DrawEllipse(&p, cy, cy, rx, ry);

	//Luu ellipse nay vao chuoi listObjects de co the Save tap tin
	stringstream list;
	list << "<ellipse cx=" << "\"" << cx << "\"" << " cy=" << "\"" << cy << "\"";
	list << " rx=" << "\"" << rx << "\"" << " ry=" << "\"" << ry << "\"";
	list << " stroke=" << "\"" << _stroke << "\""; 
	list << " stroke-width=" << "\"" << strokeWidth << "\"";
	list << " fill=" << "\"" << _fill << "\"" << "/>";
	getListObjects() += list.str();
}